import React, { Fragment } from 'react';
import { Modal, Form, Input, message } from 'antd';
import { SelectForm } from '@/components/UserForm';
import { getDict } from '@/services/components/userform';
import { cancelInterview } from '@/services/myRecruit/interview';
import Styles from './SendMail.less';

const formItemLayout = {
    labelCol: {
        md: { span: 5 }
    },
    wrapperCol: {
        md: { span: 19 }
    }
};

const CancelInterview = ({ form, onOk, onCancel, visible, setVisible, data = {}, ...rest }) => {
    console.log('===============================================>form', form);
    const { getFieldDecorator } = form;
    const { cancelInfo = {}, handleSearch = () => {} } = data;

    const handleSubmit = () => {
        form.validateFields(async (err, values) => {
            const { cancelReasonRemark, cancelReason } = values;
            const payload = {
                cancelReasonRemark,
                cancelReason,
                ...cancelInfo
            };
            console.log('===============================================>payload', payload);
            if (!err) {
                const res = await cancelInterview(payload);
                if (res && res.code === 10000) {
                    message.success(res.msg);
                    setVisible(false);
                    handleSearch(1);
                } else {
                    message.error(res.msg);
                }
            }
        });
    };

    return (
        <div>
            <Modal
                // confirmLoading={loading}
                title="取消面试"
                width={500}
                id="notice"
                onOk={handleSubmit}
                onCancel={() => {
                    onCancel();
                }}
                visible={visible}
                destroyOnClose
                {...rest}
            >
                <Form layout="horizontal" {...formItemLayout} className={Styles.sendMail}>
                    {visible && (
                        <Fragment>
                            <Form.Item label="取消原因">
                                {getFieldDecorator('cancelReason', {
                                    // initialValue: talentEmail,
                                    rules: [
                                        {
                                            required: true,
                                            message: '请选择原因'
                                        }
                                    ]
                                })(
                                    <SelectForm
                                        params={{ code: 'interviewCancelReason' }}
                                        requireParam={['code']}
                                        getData={params =>
                                            getDict(params).then(res => {
                                                if (res && res.code === 10000 && res.data) {
                                                    return res.data || [];
                                                }
                                                return [];
                                            })
                                        }
                                        fieldsName={{
                                            selectValue: 'dictValue',
                                            selectTitle: 'dictName'
                                        }}
                                        // onChange={this.companyChange}
                                        selectProps={{
                                            placeholder: '请选择取消原因',
                                            style: { minWidth: 200 }
                                        }}
                                    />
                                )}
                            </Form.Item>
                            <Form.Item label="备注">
                                {getFieldDecorator('cancelReasonRemark', {
                                    rules: [
                                        {
                                            required: true,
                                            max: 200,
                                            message: '请输入取消原因的说明，不超过200字符'
                                        }
                                    ]
                                })(<Input.TextArea rows={4} placeholder="请输入取消原因的说明，不超过200字符" />)}
                            </Form.Item>
                        </Fragment>
                    )}
                </Form>
            </Modal>
        </div>
    );
};

export default Form.create()(CancelInterview);
